package com.lfd.rabbitmq.service;

import com.lfd.rabbitmq.config.NewRabbitConfig;
import com.lfd.rabbitmq.config.RabbitConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @项目名： spring-emq
 * @包名： com.lfd.rabbitmq.service
 * @文件名: NewMessageProducer
 * @创建者: liufudong@szyh-smart.com
 * @创建时间: 2024/10/11 19:55
 * @描述：生产者发送消息：
 */
@Slf4j
@Service
public class NewMessageProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMessage(String message) {
        CorrelationData correlationData = new CorrelationData(System.currentTimeMillis() + "-uniqueId");
        rabbitTemplate.convertAndSend(NewRabbitConfig.EXCHANGE_NAME_A, NewRabbitConfig.ROUTING_KEY_A, message,correlationData);
        log.info("NewMessageProducer Message sent: {}", message);
    }
}
